<?php
/**
 * Created by PhpStorm.
 * User: hooshim
 * Date: 2014-12-03
 * Time: 오전 11:23
 */

header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
header("Pragma:no-cache");

include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.

	//## 파라미터 선언

    $payCd 			= $_POST['payCd'];
    $billCd 		= $_POST['billCd'];
    $planDt 		= $_POST['planDt'];
    $article 		= $_POST['article'];
    $amount 		= $_POST['amount'];
    $orgAmount 		= $_POST['orgAmount'];
    $tax 			= $_POST['tax'];
    $compCd 		= $_POST['compCd'];
    $flag 			= $_POST['flag'];
    $paySeq 		= $_POST['paySeq'];
    $payAmount 		= $_POST['payAmount'];
    $actionDt 		= $_POST['actionDt'];
    $bankDt 		= $_POST['bankDt'];
    $payMemo 		= $_POST['payMemo'];
    $payFlag 	    = $_POST['payFlag'];

    if($article) $article = iconvEncode($article);
    if($payMemo) $payMemo = iconvEncode($payMemo);

    if(!$amount) $amount = 0;
    if(!$orgAmount) $orgAmount = 0;
    if(!$tax) $tax = 0;
    if(!$payAmount) $payAmount = 0;
    if(!$compCd) $compCd = 0;
    if(!$paySeq) $paySeq = 0;
    if(!$payCd) $payCd = 0;
    if(!$billCd) $billCd = 0;
    if($payAmount == 0 || !$payAmount) {
        $bankDt = "";
        $actionDt = "";
    }

//@payCd varchar(10),			-- 지출 코드
//	@accountCd int,				-- 계정 코드
//	@article varchar(100),		-- 지출 내역
//	@amount numeric(18,0),		-- 금액
//	@orgAmount numeric(18,0),	-- 원금
//	@tax numeric(18,0),			-- 세금
//	@compCd	int,				-- 거래처 코드
//	@planDt varchar(10),		-- 예정일
//	@accessId varchar(20),		-- 등록자 ID
//	@actionDt varchar(10),		-- 지급일
//	@bankDt varchar(10),		-- 통장 정리일
//	@payAmount numeric(18,0),	-- 지급 금액
//	@paySeq int,					-- 지급 SEQ
//	@memo varchar(500) = '',	-- 메모
//	@payFlag varchar(2),		-- 지급 가용 여부
//	@payMethod varchar(3),		-- 결재방법
//	@billCd varchar(15),			-- BILL  NO
//	@flag varchar(2)			-- 가용여부


    if(!$issueId) $issueId = "Jade";

    $query = "EXEC spPayment ";

    $query .= "@payCd='" .$payCd ."'";
    $query .=", @article='" .$article ."'";
    $query .=", @amount='" .$amount ."'";
    $query .=", @orgAmount='" .$orgAmount ."'";
    $query .=", @tax='" .$tax ."'";
    $query .=", @compCd='" .$compCd ."'";
    $query .=", @planDt='" .$planDt ."'";
    $query .=", @accessId='" .$issueId ."'";
    $query .=", @flag='" .$flag ."'";
    $query .=", @payAmount='" .$payAmount ."'";
    $query .=", @actionDt='" .$actionDt ."'";
    $query .=", @bankDt='" .$bankDt ."'";
    $query .=", @memo='" .$payMemo ."'";
    $query .=", @payFlag='" .$payFlag ."'";
    $query .=", @paySeq='" .$paySeq ."'";
    $query .=", @payMethod='" .$payMethod ."'";
    $query .=", @billCd='" .$billCd ."'";

    $logger->debug($query ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
//    $query = iconvEncode($query);
    $rslt = mssql_query($query);
$logger->debug($rslt ." [#FROM:" . $G_remote_ip."#]");

    $result = Array();
    if ($rslt == "1") {
        $result['rsStatus'] = "Success";
        $successMsg = iconvEncode("저장 되었습니다.");
    }
    else {
        $result['rsStatus'] = "Fail";
        $successMsg = iconvEncode("저장 실패");

    }
    $result['rsStr'] = urlencode($successMsg);

    $output = json_encode($result);
    $output = urldecode($output);
    echo iconvDecode($output);
    $logger->debug($output ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
?>